package com.Liux.blog.controller;

import com.Liux.blog.entity.User;
import com.Liux.blog.service.UserService;
import com.Liux.blog.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param username 账号
     * @param pwd 密码
     * @return
     */
    @PostMapping("/login")
    public ResultVo login(String username,String pwd){
        return userService.loginUser(username,pwd);
    }

    /**
     * 注册
     * @param user 用户信息
     * @return
     */
    @PostMapping("/regist")
    public ResultVo regist(User user){
        return userService.addUser(user);
    }

    @GetMapping("/list")
    public ResultVo listUser(int pageNum,int limit){
        return userService.listUser(pageNum,limit);
    }

    @PostMapping("/update")
    public ResultVo update(String id,String nikeName,String signature){
        return userService.updateUser(id,nikeName,signature);
    }
    @DeleteMapping("/del")
    public ResultVo del(String id){
        return  userService.delUser(id);
    }

    @GetMapping("/like")
    public ResultVo like(String nikeName,int pageNum,int limit){
        return userService.LikeUser(nikeName,pageNum,limit);
    }

}
